package com.share.finance.risk.common.enums;

import lombok.Getter;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

@Getter
public enum ResultEnum {
    PSSS("psss", "通过"),
    REJECT("reject", "拒绝"),
    EXCEPTION("exception", "异常"),
    BREAKPOINT("breakpoint", "断点"),
    UNKNOWN("unknown", "未知");

    //编码
    public String code;

    //主题名字
    public String name;


    ResultEnum(final String code, final String name) {
        this.code = code;
        this.name = name;
    }

    public static ResultEnum toEnum(final String code) {
        for (final ResultEnum tag : ResultEnum.values()) {
            if (tag.code.equals(code)) {
                return tag;
            }
        }
        return null;
    }

    public static String toName(final String code) {
        return Optional.ofNullable(toEnum(code)).map(item -> item.name).orElse(null);
    }

    public static List<String> listCode() {
        List<String> list = new LinkedList<>();
        for (ResultEnum typeEnum : ResultEnum.values()) {
            list.add(typeEnum.code);
        }
        return list;
    }
}
